@layout("/common/_curd/_container.html"){

<script type="text/javascript">
	var ctx = "${basePath}";
	var grid_selector = "#grid-table";
	var pager_selector = "#grid-pager";
	
	$(function(){
		initGrid();
		initMenuBtn("btns", "${code}");
	});
	
	function initGrid(){
		var grid_url = ctx + "/${code}/list";
		var _colnames = ["ID",
						"班级名称",
						"年级",
                        "班主任",
                        "班主任",
                        "课任老师",
                        "课任老师",
                        "学生人数",
                        "操作"];
		var _colmodel = [{name:"id", index:"id",hidden:true},
						{name:"class_name", index:"class_name", width:50},
						{name:"dict_grade_id", index:"grade_id", width:50},
                        {name:"head_teacher", index:"head_teacher",hidden:true},
                        {name:"head_teacher_name", index:"head_teacher_name", width:100},
                        {name:"teachers", index:"teachers",hidden:true},
                        {name:"subject_teacher_names", index:"teachers", width:100},
                        {name:"stu_count", index:"stu_count", width:100},
                        {name: 'id',formatter:fmatterOperation, width:200,sortable:false}
                        ];
		
		jQuery(grid_selector).jqGrid({
			url : grid_url,
		    shrinkToFit : true,
			colNames : _colnames,
			colModel : _colmodel, 
			jsonReader : {id :"id"},
			pager : pager_selector,
			postData : {sort : "id", order : "desc"}
		});
	}
    function fmatterOperation(cellvalue, options, rowObject){
        var result =  '<button class="btn btn-primary btn-sm" onclick="chooseHeadTeacher('+cellvalue+','+rowObject.head_teacher+')">选择班主任</button>'
                +'<button class="btn btn-success btn-sm" onclick="chooseSubjectTeacher('+cellvalue+',\''+rowObject.teachers+'\')">分配课任老师</button>';
        if(rowObject.stu_chat_id && rowObject.parent_chat_id){
            result +='<button class="btn btn-default disabled btn-sm">群聊已创建</button>';
        }else{
            result +='<button class="btn btn-warning btn-sm" onclick="createGroupChat('+cellvalue+')">创建群聊</button>';
        }
        return result;
    }

    function chooseHeadTeacher(id,sels){
        ///chooseTeacher(id,"选择班主任","radio","headTeacherCallback");
        new teacher_tree(
                {
                    'id' : id,
                    'title' : '选择班主任',
                    'check_type' : 'radio',
                    'callback' : 'headTeacherCallback',
                    'value' : sels
                }
        ).choose();
    }
    function chooseSubjectTeacher(id,sels){
        //chooseTeacher(id,"分配课任老师","checkbox","subjectTeacherCallback")
        new teacher_tree(
                {
                    'id' : id,
                    'title' : '分配课任老师',
                    'check_type' : 'checkbox',
                    'callback' : 'subjectTeacherCallback',
                    'value' : sels.substring(1,sels.length-1)
                }
        ).choose();
    }
    function createGroupChat(id){
        var ajax = new $ax(ctx + "/${code}/createGroupChat", function(data){
            if (data.code === 0) {
                layer.msg(data.message, {shift: 1});
                reloadGrid();
                return false;
            } else {
                layer.msg(data.message, {shift: 6});
                return false;
            }
        });
        ajax.data = {"id":id};
        ajax.start();
    }
    function headTeacherCallback(id,ids,names){
        console.log(id+"-"+ids+"-"+names);
        var ajax = new $ax(ctx + "/${code}/chooseHeadTeacher", function(data){
            if (data.code === 0) {
                layer.msg(data.message, {shift: 1});
                reloadGrid();
                return false;
            } else {
                layer.msg(data.message, {shift: 6});
                return false;
            }
        });
        ajax.data = {"id":id,"teacherId":ids};
        ajax.start();
    }

    function subjectTeacherCallback(id,ids,names){
        console.log(id+"-"+ids+"-"+names);
        var ajax = new $ax(ctx + "/${code}/chooseSubjectTeacher", function(data){
            if (data.code === 0) {
                layer.msg(data.message, {shift: 1});
                reloadGrid();
                return false;
            } else {
                layer.msg(data.message, {shift: 6});
                return false;
            }
        });
        ajax.data = {"id":id,"teachers":ids};
        ajax.start();
    }
</script>

    <div class="row">
        <div class="col-xs-12">
            <div class="row-fluid" style="margin-bottom: 5px;">
                <div class="tabbable">
                    <ul class="nav nav-tabs padding-12 tab-color-blue background-blue" id="myTab4">
                        <li class="active">
                            <a data-toggle="tab" href="#" onclick="javascript:window.location.href='${basePath}/${code}'" aria-expanded="true">在校班级</a>
                        </li>
                        <li >
                            <a data-toggle="tab" href="#" onclick="javascript:window.location.href='${basePath}/${code}/graduate'" aria-expanded="false">毕业班级</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
	<!-- 配置 grid -->
	<div class="row">
		<div class="col-xs-12 tb-grid">
			<!-- 配置 查询 -->
			@ var _col=[
@		{name:"", index:"id", type:"text"},
			@		{name:"", index:"class_name", type:"text"},
			@		{name:"dict表grade类型", index:"grade_id", type:"text"},
			@		{name:"学生人数", index:"stu_count", type:"text"},
			@		{name:"学生部门id", index:"stu_dept_id", type:"text"},
			@		{name:"家长部门id", index:"parent_dept_id", type:"text"},
			@		{name:"学生群聊", index:"stu_chat_id", type:"text"},
			@		{name:"家长群聊", index:"parent_chat_id", type:"text"},
			@		{name:"课任老师", index:"teachers", type:"text"},
			@		{name:"是否毕业1未毕业2毕业", index:"is_graduate", type:"text"},
			@		{name:"毕业年份", index:"graduate_year", type:"text"}
			@];
			<!--include("/common/_function/_search.html",{"col":_col}){}-->
			<!-- 按钮 -->
			<div class="welljq well-sm" id="btns"></div>
			<!-- grid -->
			<table id="grid-table"></table>
			<!-- 分页-->
			<div id="grid-pager"></div>
		</div>
	</div>
	
	<!-- 引入所需的js -->
	@include("/common/_listscript.html"){}
    <script src="${basePath}/static/biz/teacher_tree.js" type="text/javascript" ></script>
@}	